﻿using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.SelfHost;
using Crow.Library.Host.Configuration;

namespace Crow.Library.Host
{
    internal class AspNetSelfHosting : IHttpHost
    {
        private HttpSelfHostServer _server;

        #region IHttpHost Members

        public void InitializeHost(HttpConfiguration configuration, HttpMessageHandler messageHandler,
                                   ITypeListHost typeList)
        {
            _server = new HttpSelfHostServer(configuration as HttpSelfHostConfiguration, messageHandler);
        }

        public Task OpenAsync()
        {
            return _server.OpenAsync();
        }

        public Task CloseAsync()
        {
            return _server.CloseAsync();
        }

        public void Dispose()
        {
            _server.Dispose();
        }

        #endregion
    }
}